<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>空间分析服务-地形曲率计算</title>

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>

<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
<script type="text/javascript" src="../../dist/iclient9-leaflet.min.js"></script>
<script type="text/javascript">
    var map, terrainCurvatureCalculationService, terrainCurvatureCalculationParameters, terrainCurvatureCalculationResult,
        themeService, themeGridRange, themeParameters, themeLayer,
        baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-jingjin/rest/maps/京津地区地图",
        serviceUrl = "http://support.supermap.com.cn:8090/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
    map = L.map('map', {
        crs: L.CRS.EPSG4326,
        center: [39.79, 116.85],
        maxZoom: 18,
        zoom: 6
    });
    L.supermap.tiledMapLayer(baseUrl, { noWrap: true}).addTo(map).on("load", function () {
        terrainCurvatureCalculationProcess();
    });

    function terrainCurvatureCalculationProcess() {
        //创建地形曲率计算服务实例
        terrainCurvatureCalculationService = L.supermap.spatialAnalystService(serviceUrl);
        //创建地形曲率计算参数实例
        terrainCurvatureCalculationParameters = new SuperMap.TerrainCurvatureCalculationParameters({
            dataset: "JingjinTerrain@Jingjin",
            zFactor: 1.0,
            averageCurvatureName: "CurvatureA",
            deleteExistResultDataset: true
        });
        //向iServer发起地形曲率计算请求
        terrainCurvatureCalculationService.terrainCurvatureCalculate(terrainCurvatureCalculationParameters, function (serviceResult) {
            terrainCurvatureCalculationResult = serviceResult.result;
            //用栅格专题图展示分析结果
            showAnalysisResult_ThemeGridRange();
        });
    }

    function showAnalysisResult_ThemeGridRange() {
        themeService = L.supermap.themeService(baseUrl);
        var themeGridRangeIteme1 = new SuperMap.ThemeGridRangeItem({
                start: -9000000,
                end: -1000,
                color: new SuperMap.ServerColor(0, 0, 255)
            }),
            themeGridRangeIteme2 = new SuperMap.ThemeGridRangeItem({
                start: -1000,
                end: -1,
                color: new SuperMap.ServerColor(0, 0, 125)
            }),
            themeGridRangeIteme3 = new SuperMap.ThemeGridRangeItem({
                start: -1,
                end: 1,
                color: new SuperMap.ServerColor(0, 125, 125)
            }),
            themeGridRangeIteme4 = new SuperMap.ThemeGridRangeItem({
                start: 1,
                end: 1000,
                color: new SuperMap.ServerColor(0, 125, 0)
            }),
            themeGridRangeIteme5 = new SuperMap.ThemeGridRangeItem({
                start: 1000,
                end: 20000000,
                color: new SuperMap.ServerColor(0, 255, 0)
            });
        themeGridRange = new SuperMap.ThemeGridRange({
            reverseColor: false,
            rangeMode: SuperMap.RangeMode.EQUALINTERVAL,
            //栅格分段专题图子项数组
            items: [themeGridRangeIteme1,
                themeGridRangeIteme2,
                themeGridRangeIteme3,
                themeGridRangeIteme4,
                themeGridRangeIteme5
            ]
        });
        themeParameters = new SuperMap.ThemeParameters({
            //制作专题图的数据集（地形曲率计算的结果数据集）
            datasetNames: [terrainCurvatureCalculationResult.averageCurvatureResult.dataset.split('@')[0]],
            dataSourceNames: ["Jingjin"],
            joinItems: null,
            themes: [themeGridRange]
        });
        themeService.getThemeInfo(themeParameters, function (serviceResult1) {
            var result = serviceResult1.result;
            if (result && result.newResourceID) {
                themeLayer = L.supermap.tiledMapLayer(baseUrl, {
                    noWrap: true,
                    cacheEnabled: false,
                    transparent: true,
                    layersID: result.newResourceID
                }).addTo(map);
            }
        })
    }
</script>
</body>
</html>